/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.memberorder.service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

import com.alibaba.druid.sql.visitor.functions.If;
import com.jeeplus.config.swagger.IgnoreSwaggerParameter;
import com.jeeplus.modules.commission.entity.Commission;
import com.jeeplus.modules.commission.service.CommissionService;
import com.jeeplus.modules.goods.entity.Goods;
import com.jeeplus.modules.goods.service.GoodsService;
import com.jeeplus.modules.member.entity.Member;
import com.jeeplus.modules.member.service.MemberService;
import com.jeeplus.modules.ratio.entity.Ratio;
import com.jeeplus.modules.ratio.service.RatioService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.common.usermodel.fonts.FontGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.memberorder.entity.MemberOrder;
import com.jeeplus.modules.memberorder.mapper.MemberOrderMapper;

/**
 * 用户订单Service
 *
 * @author zhych
 * @version 2021-11-16
 */
@Service
@Transactional(readOnly = true)
public class MemberOrderService extends CrudService<MemberOrderMapper, MemberOrder> {

    @Autowired
    private MemberService memberService;

    @Autowired
    private RatioService ratioService;

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private CommissionService commissionService;

    public MemberOrder get(String id) {
        return super.get(id);
    }

    public List<MemberOrder> findList(MemberOrder memberOrder) {
        return super.findList(memberOrder);
    }

    public Page<MemberOrder> findPage(Page<MemberOrder> page, MemberOrder memberOrder) {
        return super.findPage(page, memberOrder);
    }

    @Transactional(readOnly = false)
    public void save(MemberOrder memberOrder) {
        super.save(memberOrder);
    }

    @Transactional(readOnly = false)
    public void delete(MemberOrder memberOrder) {
        super.delete(memberOrder);
    }

    /**
     * 收货
     *
     * @param order 订单
     */
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public void confirmOrder(MemberOrder order) {
        // 修改订单的状态
        order.setTakeDate(new Date());
        order.setOrderState("4");
        super.save(order);
    }


    /**
     * 自动收货订单保存
     *
     * @param dataList 订单列表
     */
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public void takeOrder(List<MemberOrder> dataList) {
        for (MemberOrder memberOrder : dataList) {
            super.save(memberOrder);
        }
    }
}